package com.qian.ddj.web.controller;

import com.qian.api.ddj.model.LoginLog;
import com.qian.api.ddj.service.ILoginLogService;
import com.yaowk.api.common.PageReq;
import com.yaowk.api.common.PageResp;
import com.yaowk.web.system.security.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("ddj/loginLog")
@Api(tags = "登录日志")
public class LoginLogController {

    @Autowired
    private ILoginLogService loginLogService;

    @GetMapping("last")
    @ApiOperation("最后登录")
    public LoginLog last() {
        LoginLog loginLog = loginLogService.findLastOneByUserId(SecurityUtils.getUserId());
        return loginLog;
    }

    @GetMapping
    @ApiOperation("登录记录")
    public PageResp<LoginLog> list(PageReq pageReq) {
        LoginLog loginLog = new LoginLog();
        loginLog.setUserId(SecurityUtils.getUserId());
        PageResp<LoginLog> page = loginLogService.findAll(loginLog, pageReq);
        return page;
    }
}
